home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / ToolTipPanel.java < prev    next >
Text File  |  1998-06-30  |  10KB  |  275 lines

  1. /*
  2.  * @(#)ToolTipPanel.java    1.15 98/03/17
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.accessibility.*;
  23.  
  24. import java.awt.*;
  25. import java.awt.event.*;
  26. import java.lang.*;
  27.  
  28. /*
  29.  * @version 1.15 03/17/98
  30.  * @author Jeff Dinkins
  31.  * @author Peter Korn (accessibility support)
  32.  */
  33. public class ToolTipPanel extends JPanel {
  34.     SwingSet swing;
  35.  
  36.     public ToolTipPanel(SwingSet swing) {
  37.     this.swing = swing;
  38.     loadCow();
  39.     }
  40.  
  41.     public void loadCow() {
  42.         setBackground(Color.white);
  43.     setBorder(swing.etchedBorder10);
  44.         setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
  45.     Cow cow = new Cow();
  46.     cow.setToolTipText("Cow.");
  47.     cow.getAccessibleContext().setAccessibleName("Cow image");
  48.     add(Box.createRigidArea(new Dimension(1, 40)));
  49.     add(cow);
  50.     }
  51.  
  52.     class Cow extends JLabel {
  53.     Polygon cowgon = new Polygon();
  54.  
  55.         public Cow() {
  56.          super(SwingSet.sharedInstance().loadImageIcon("images/cow.gif","Black and white cow"));
  57.         setAlignmentX(CENTER_ALIGNMENT);
  58.         cowgon.addPoint(3,20);    cowgon.addPoint(44,4);
  59.         cowgon.addPoint(79,15);   cowgon.addPoint(130,11);
  60.         cowgon.addPoint(252,5);   cowgon.addPoint(181,17);
  61.         cowgon.addPoint(301,45);  cowgon.addPoint(292,214);
  62.         cowgon.addPoint(269,209); cowgon.addPoint(266,142);
  63.         cowgon.addPoint(250,161); cowgon.addPoint(235,218);
  64.         cowgon.addPoint(203,206); cowgon.addPoint(215,137);
  65.         cowgon.addPoint(195,142); cowgon.addPoint(143,132);
  66.         cowgon.addPoint(133,189); cowgon.addPoint(160,200);
  67.         cowgon.addPoint(97,196);  cowgon.addPoint(107,182);
  68.         cowgon.addPoint(118,185); cowgon.addPoint(110,144);
  69.         cowgon.addPoint(59,77);   cowgon.addPoint(30,82);
  70.         cowgon.addPoint(30,35);   cowgon.addPoint(15,36);
  71.         }
  72.  
  73.     boolean moo = false;
  74.     boolean milk = false;
  75.     boolean tail = false;
  76.     public boolean contains(int x, int y) {
  77.         if((x > 30) && (x < 60) && (y > 60) && (y < 85)) {
  78.             if(!moo) {
  79.                setToolTipText("Mooooo");
  80.            moo = true;
  81.            milk = false;
  82.            tail = false;
  83.         }
  84.         } else if((x > 150) && (x < 230) && (y > 90) && (y < 145)) {
  85.             if(!milk) {
  86.                setToolTipText(" Got  Milk? ");
  87.            milk = true;
  88.            moo = false;
  89.            tail = false;
  90.         }
  91.         } else if((x > 280) && (x < 300) && (y > 20) && (y < 175)) {
  92.             if(!tail) {
  93.                setToolTipText("Tail.");
  94.            tail = true;
  95.            moo = false;
  96.            milk = false;
  97.         }
  98.         } else if(moo || milk || tail) {
  99.             setToolTipText("Cow.");
  100.         moo = false;
  101.         tail = false;
  102.         milk = false;
  103.         }
  104.         if(cowgon.contains(new Point(x, y))) {
  105.         return true;
  106.         } else {
  107.         return false;
  108.         }
  109.     }
  110.     }
  111.  
  112.     public void itsEaster(boolean b) {
  113.     if(!b) {
  114.        removeAll();
  115.        loadCow();
  116.     } else {
  117.        removeAll();
  118.        setBackground(Color.black);
  119.        setLayout(new BorderLayout());
  120.        Easter easter = new Easter();
  121.        add(easter, BorderLayout.CENTER);
  122.        invalidate();
  123.        validate();
  124.        easter.go();
  125.     }
  126.     }
  127.  
  128.     class Easter extends JComponent implements ActionListener {
  129.     Timer animator;
  130.  
  131.     private ImageIcon amy     = SwingSet.sharedInstance().loadImageIcon("images/people/amy.gif", "Amy Fowler");
  132.     private ImageIcon jag     = SwingSet.sharedInstance().loadImageIcon("images/people/jag.gif", "James Gosling");
  133.     private ImageIcon jeff    = SwingSet.sharedInstance().loadImageIcon("images/people/jeff.gif", "Jeff Dinkins");
  134.     private ImageIcon tim     = SwingSet.sharedInstance().loadImageIcon("images/people/tim.gif", "Tim Prinzing");
  135.     private ImageIcon tom     = SwingSet.sharedInstance().loadImageIcon("images/people/tom.gif", "Tom Ball");
  136.         private ImageIcon rick    = SwingSet.sharedInstance().loadImageIcon("images/people/rick.gif", "Rick Levenson");
  137.         private ImageIcon hans1   = SwingSet.sharedInstance().loadImageIcon("images/people/mathew.gif", "Mathew Muller");
  138.         private ImageIcon hans2   = SwingSet.sharedInstance().loadImageIcon("images/people/pl.gif", "Project Lead");
  139.         private ImageIcon ges     = SwingSet.sharedInstance().loadImageIcon("images/people/ges.gif", "Georges Saab");
  140.         private ImageIcon phil    = SwingSet.sharedInstance().loadImageIcon("images/people/phil.gif", "Phillip Milne");
  141.         private ImageIcon arnaud  = SwingSet.sharedInstance().loadImageIcon("images/people/nathan.gif", "Arnaud Webber");        
  142.         private ImageIcon rich    = SwingSet.sharedInstance().loadImageIcon("images/people/rich.gif", "Rich Schiavi");
  143.  
  144.     int tmpScale;
  145.     
  146.     private double x1 = 0;
  147.     private double y1 = 0;
  148.  
  149.     private double x2 = 0;
  150.     private double y2 = 0;
  151.     
  152.     private int xAmy = 0;
  153.     private int xJag = 0;
  154.     private int xJeff = 0;
  155.     private int xTim = 0;
  156.     private int xTom = 0;
  157.     private int xRick = 0;
  158.     private int xHans = 0;
  159.         private int xGes = 0;
  160.         private int xPhil = 0;
  161.         private int xArnaud = 0;
  162.         private int xRich = 0;
  163.     
  164.     private int yAmy = 0;
  165.     private int yJag = 0;
  166.     private int yJeff = 0;
  167.     private int yTim = 0;
  168.     private int yTom = 0;
  169.     private int yRick = 0;
  170.     private int yHans = 0;
  171.     private int yGes = 0;
  172.     private int yPhil = 0;
  173.     private int yArnaud = 0;
  174.     private int yRich = 0;
  175.  
  176.     public Easter() {
  177.     }
  178.  
  179.     public void go() {
  180.         animator = new Timer(22 + 22 + 22, this);
  181.         animator.start();
  182.     }
  183.  
  184.     public void paint(Graphics g) {
  185.         // The code may be goofy, but the code be havin' some fun.
  186.         g.setColor(getParent().getBackground());
  187.         g.fillRect(0, 0, getWidth(), getHeight());
  188.  
  189.         // Unless your name is Jeff Dinkins, don't muck with this. (-:
  190.         tmpScale = (int) (Math.abs(Math.sin(x1+00)) * 10); double jeffScale   = (double) tmpScale / 10;
  191.         tmpScale = (int) (Math.abs(Math.sin(x1+10)) * 10); double timScale    = (double) tmpScale / 10;
  192.         tmpScale = (int) (Math.abs(Math.sin(x1+20)) * 10); double tomScale    = (double) tmpScale / 10;
  193.         tmpScale = (int) (Math.abs(Math.sin(x1+30)) * 10); double jagScale    = (double) tmpScale / 10;
  194.         tmpScale = (int) (Math.abs(Math.sin(x1+40)) * 11); double amyScale    = (double) tmpScale / 10;
  195.         tmpScale = (int) (Math.abs(Math.sin(x1+50)) * 11); double rickScale   = (double) tmpScale / 10;
  196.         tmpScale = (int) (Math.abs(Math.sin(x2+60)) * 11); double hansScale   = (double) tmpScale / 10;
  197.         tmpScale = (int) (Math.abs(Math.sin(x2+70)) * 10); double gesScale    = (double) tmpScale / 10;
  198.         tmpScale = (int) (Math.abs(Math.sin(x1+10)) * 10); double philScale   = (double) tmpScale / 10;
  199.         tmpScale = (int) (Math.abs(Math.sin(x1+90)) * 10); double arnaudScale = (double) tmpScale / 10;
  200.             tmpScale = (int) (Math.abs(Math.sin(x1+80)) * 10); double richScale   = (double) tmpScale / 10;
  201.         
  202.         x1 +=.1;
  203.         x2 +=.065;
  204.         int nudgeX = (int) (((double) getWidth()/2) * .8);
  205.         xTom       = (int) (Math.sin(x1+00) * nudgeX) + nudgeX;
  206.             xAmy       = (int) (Math.sin(x1+10) * nudgeX) + nudgeX;
  207.         xGes       = (int) (Math.sin(x2+20) * nudgeX) + nudgeX;
  208.             xRick      = (int) (Math.sin(x1+30) * nudgeX) + nudgeX;
  209.         xJeff      = (int) (Math.sin(x1+40) * nudgeX) + nudgeX;
  210.             xPhil      = (int) (Math.sin(x1+51) * nudgeX) + nudgeX;          
  211.         xTim       = (int) (Math.sin(x1+60) * nudgeX) + nudgeX;
  212.         xRich      = (int) (Math.sin(x1+65) * nudgeX) + nudgeX;
  213.             xArnaud    = (int) (Math.sin(x1+70) * nudgeX) + nudgeX;
  214.             xHans      = (int) (Math.sin(x2+85) * nudgeX) + nudgeX;
  215.         xJag       = (int) (Math.sin(x1+90) * nudgeX) + nudgeX;
  216.         
  217.         y1 +=.1;
  218.         y2 +=.05;
  219.         int nudgeY    = (int) (((double) getHeight()/2) * .60);
  220.         int nudgeMe   = (int) (((double) getHeight()/2) * .45);
  221.         int nudgePhil = (int) (((double) getHeight()/2) * .20);
  222.         yTom          = (int) (Math.sin(y1+00) * nudgeY)    + nudgeY;
  223.         yTim          = (int) (Math.sin(y1+10) * nudgeY)    + nudgeY;
  224.         yRich         = (int) (Math.sin(y1+15) * nudgeY)    + nudgeY;
  225.         yJeff         = (int) (Math.sin(y1+20) * nudgeMe)   + nudgeY;
  226.             yHans         = (int) (Math.sin(y2+33) * nudgeY)    + nudgeY;
  227.             yPhil         = (int) (Math.sin(y1+45) * nudgePhil) + nudgeY;
  228.             yAmy          = (int) (Math.sin(y1+50) * nudgeY)    + nudgeY;
  229.             yArnaud       = (int) (Math.sin(y1+60) * nudgeY)    + nudgeY;
  230.             yGes          = (int) (Math.sin(y2+70) * nudgeY)    + nudgeY;
  231.             yRick         = (int) (Math.sin(y1+80) * nudgeMe)   + nudgeY;
  232.         yJag          = (int) (Math.sin(y1+90) * nudgeY)    + nudgeY;
  233.  
  234.         // Don't modify this - the order matters!
  235.         if(x1 > 30) squish(g, arnaud, xArnaud, yArnaud, arnaudScale);
  236.         if(x1 > 15) squish(g, phil,   xPhil,   yPhil,   philScale);
  237.         if(x1 >  9) squish(g, rick,   xRick,   yRick,   rickScale);
  238.         if(x1 > 27) squish(g, tim,    xTim,    yTim,    timScale);
  239.         if(x1 > 12) squish(g, tom,    xTom,    yTom,    tomScale);
  240.             if(x1 > 18) squish(g, rich, xRich, yRich, richScale);
  241.         if(x1 > 33) {
  242.         if(hansScale > .65) {
  243.             squish(g, hans1,   xHans,   yHans,   hansScale);
  244.         } else {
  245.             squish(g, hans2,   xHans,   yHans,   hansScale);
  246.         }
  247.         }
  248.         if(x1 > 21) squish(g, amy,    xAmy,    yAmy,    amyScale);
  249.         if(x1 > 6) squish(g, jag,    xJag,    yTom,    jagScale);
  250.         squish(g, jeff,   xJeff,   yJeff,   jeffScale);
  251.         if(x1 > 3) squish(g, ges,    xGes,    yGes,    gesScale);
  252.  
  253.     }
  254.  
  255.     public void squish(Graphics g, ImageIcon icon, int x, int y, double scale) {
  256.         if(isVisible()) {
  257.         g.drawImage(icon.getImage(),
  258.                 x, y,
  259.                 (int) (icon.getIconWidth()*scale),
  260.                 (int) (icon.getIconHeight()*scale),
  261.                 this);
  262.         }
  263.     }
  264.  
  265.     public void actionPerformed(ActionEvent e) {
  266.         if(isVisible()) {
  267.         repaint();
  268.         } else {
  269.         animator.stop();
  270.         }
  271.     }
  272.     }
  273.  
  274. }
  275.